<?php

/**
 * 相关session,cookie的保存
 *
 * @author jiang
 */

namespace Kj\Admin\Libraries;

use Session, Cookie;
use Kj\Admin\Libraries\Acl;
use Kj\Admin\Models\User;

class SessionCookieStore
{
    /**
     * 设置用户权限的key
     *
     * @var string
     */
    private $_userAclSessionKey = '___user_acl_session';

    /**
     * 设置当前顶级菜单的key
     *
     * @var string
     */
    private $_currentMenuPidKey = '___current_menu_pid';

    /**
     * 设置当前二级菜单的key
     *
     * @var string
     */
    private $_currentMenuSidKey = '___current_menu_sid';
    
    /**
     * 上传文件，获取临时未处理文件列表所用到的key
     *
     * @var string
     */
    private $_attJsonKey = 'att_json';
    
    /**
     * 初始化
     *
     * @access public
     */
    public function __construct()
    {
        //todo
    }

    /**
     * 把用户的权限保存到session中，方便系统使用。
     * 
     * @param Jiang\Backend\Libraries\Acl $aclObj
     * @param Jiang\Backend\Models\User $userObj
     * @access public
     * @return true|false
     */
    public function setUserPermissionSession(Acl $aclObj, User $userObj)
    {
        $userAclInfo = $aclObj->getUserAccessPermission($userObj);
        return Session::put($this->_userAclSessionKey, $userAclInfo);
    }
    
    /**
     * 返回保存在session中的用户权限信息
     *
     * @access public
     */
    public function getUserPermissionSession()
    {
        return Session::get($this->_userAclSessionKey);
    }

    /**
     * 当前请求的菜单ID
     *
     * @access public
     */
    public function setCurrentMenuPid($id)
    {
        return Session::put($this->_currentMenuPidKey, $id);
    }

    /**
     * 返回当前请求的菜单ID
     *
     * @access public
     */
    public function getCurrentMenuPid()
    {
        return Session::get($this->_currentMenuPidKey);
    }

    /**
     * 当前请求的二级菜单ID
     *
     * @access public
     */
    public function setCurrentMenuSid($id)
    {
        return Session::put($this->_currentMenuSidKey, $id);
    }

    /**
     * 返回当前请求的二级菜单ID
     *
     * @access public
     */
    public function getCurrentMenuSid()
    {
        return Session::get($this->_currentMenuSidKey);
    }
    
    /**
     * 设置文件上传时未处理的cookie
     *
     * @access public
     */
    public function setAttJson($data, $min)
    {
        return Cookie::make($this->_attJsonKey, $data, $min);
    }
    
    /**
     * 返回设置文件上传时未处理的cookie
     *
     * @access public
     */
    public function getAttJson()
    {
        return Cookie::get($this->_attJsonKey);
    }

}
